﻿package de.gameduell.framework.facebook.app.popups {
	import de.gameduell.framework.debug.Debug;

	import flash.events.Event;

	public class InterstitialPopup extends PyramidBasePopup {
		private const GD:String = "gd";
		private const FRIENDS:String = "friends";
		private const IPHONE:String = "iphone";
		
		private var interstitialID:String;
		private var interstitialPopupID:String;
		private var interstitialPopupBaseID:String;
		private var interstitialType:String;

		public function InterstitialPopup(aInterstitialID:String) {
			interstitialID = aInterstitialID;
			switch(interstitialID){
				case "gd_interstitial_01":
					interstitialPopupID = "gd_interstitial_01_popup";
					interstitialType = GD;
					interstitialPopupBaseID = "interstitialPopup_GD";
					break;
					
				case "gd_interstitial_02":
					interstitialPopupID = "gd_interstitial_02_popup";
					interstitialType = GD;
					interstitialPopupBaseID = "interstitialPopup_GD";
					break;
					
				case "get_friends_interstitial_01":
					interstitialPopupID = "get_friends_interstitial_01_popup";
					interstitialType = FRIENDS;
					interstitialPopupBaseID = "generic_2_buttons_header_content";
					break;
					
				default: // just in case
					interstitialPopupID = "get_friends_interstitial_01_popup";
					interstitialType = FRIENDS;
					interstitialPopupBaseID = "generic_2_buttons_header_content";
			}
			Debug.trace("InterstitialPopup::InterstitialPopup: " + interstitialPopupBaseID + ":" + interstitialPopupID + " reasonString: " + aInterstitialID, Debug.DEBUG);
			super(interstitialPopupBaseID, interstitialPopupID, 0, false);
			
			registerButton("skipButton", hide);
			if(interstitialType == GD || interstitialType == IPHONE){
				registerButton("okButton", doGDInterstitialAction);
			}else{
				registerButton("okButton", doFriendsInterstitialAction);
			}
		}

		private function doGDInterstitialAction(event:Event):void {
			tracker.track(interstitialID);
			var urlString:String = locale.loadString(interstitialPopupID + ".actionLink");
			controller.redirectTo(urlString);
			hide();
		}

		private function doFriendsInterstitialAction(event:Event):void {
			tracker.track(interstitialID);
			controller.inviteFriends();
			hide();
		}
	}
}
